package com.xzx.mr.writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author xinzhixuan
 * @version V1.0
 * @date 2019/7/15 21:24
 */
public class FlowCountMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    private Text outputKey = new Text();
    private FlowBean outputValue = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //一行一行的获取
        String line = value.toString();
        String[] fields = line.split("\t");
        String phoneNumber = fields[1];
        String upFlow = fields[fields.length - 3];
        String downFlow = fields[fields.length - 2];

        outputKey.set(phoneNumber);
        outputValue.setUpFlow(Long.parseLong(upFlow));
        outputValue.setDownFlow(Long.parseLong(downFlow));

        context.write(outputKey, outputValue);
    }
}
